import { createRouter, createWebHistory } from 'vue-router'

// 登录页面
const Login = () => import('../views/Login.vue')
const MainLayout = () => import('../layouts/MainLayout.vue')

// 平台概览模块
const SystemMonitor = () => import('../views/dashboard/system-monitor/Index.vue')
const OperationData = () => import('../views/dashboard/operation-data/Index.vue')
const ServiceStatus = () => import('../views/dashboard/service-status/Index.vue')

// 租户管理模块
const Organization = () => import('../views/tenant/organization/Index.vue')
const User = () => import('../views/tenant/user/Index.vue')
const Package = () => import('../views/tenant/package/Index.vue')
const Billing = () => import('../views/tenant/billing/Index.vue')

// 财务管理模块
const Income = () => import('../views/finance/income/Index.vue')
const Cost = () => import('../views/finance/cost/Index.vue')
const Report = () => import('../views/finance/report/Index.vue')

// 系统运维模块
const SysMonitor = () => import('../views/system/monitor/Index.vue')
const Log = () => import('../views/system/log/Index.vue')
const Data = () => import('../views/system/data/Index.vue')
const Performance = () => import('../views/system/performance/Index.vue')

// 运营支持模块
const Ticket = () => import('../views/support/ticket/Index.vue')
const Announcement = () => import('../views/support/announcement/Index.vue')
const Knowledge = () => import('../views/support/knowledge/Index.vue')
const Customer = () => import('../views/support/customer/Index.vue')

// 安全管理模块
const Permission = () => import('../views/security/permission/Index.vue')
const SecurityMonitor = () => import('../views/security/monitor/Index.vue')
const Compliance = () => import('../views/security/compliance/Index.vue')
const Error = () => import('../views/Error.vue')

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 登录页面
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    // 平台概览
    {
      path: '/',
      component: MainLayout,
      redirect: '/dashboard/system-monitor',
      children: [
        {
          path: '/dashboard',
          redirect: '/dashboard/system-monitor',
        },
        {
          path: '/dashboard/system-monitor',
          name: 'system-monitor',
          component: SystemMonitor,
          meta: { title: '系统监控大屏' }
        },
        {
          path: '/dashboard/operation-data',
          name: 'operation-data',
          component: OperationData,
          meta: { title: '运营数据看板' }
        },
        {
          path: '/dashboard/service-status',
          name: 'service-status',
          component: ServiceStatus,
          meta: { title: '服务状态监控' }
        }
      ]
    },
    // 租户管理
    {
      path: '/tenant',
      component: MainLayout,
      redirect: '/tenant/organization',
      children: [
        {
          path: '/tenant/organization',
          name: 'organization',
          component: Organization,
          meta: { title: '组织管理' }
        },
        {
          path: '/tenant/user',
          name: 'user',
          component: User,
          meta: { title: '用户管理' }
        },
        {
          path: '/tenant/package',
          name: 'package',
          component: Package,
          meta: { title: '套餐管理' }
        },
        {
          path: '/tenant/billing',
          name: 'billing',
          component: Billing,
          meta: { title: '租户账单' }
        }
      ]
    },
    // 财务管理
    {
      path: '/finance',
      component: MainLayout,
      redirect: '/finance/income',
      children: [
        {
          path: '/finance/income',
          name: 'income',
          component: Income,
          meta: { title: '平台收入管理' }
        },
        {
          path: '/finance/cost',
          name: 'cost',
          component: Cost,
          meta: { title: '费用配置' }
        },
        {
          path: '/finance/report',
          name: 'report',
          component: Report,
          meta: { title: '财务报表' }
        }
      ]
    },
    // 系统运维
    {
      path: '/system',
      component: MainLayout,
      redirect: '/system/monitor',
      children: [
        {
          path: '/system/monitor',
          name: 'sys-monitor',
          component: SysMonitor,
          meta: { title: '服务监控' }
        },
        {
          path: '/system/log',
          name: 'log',
          component: Log,
          meta: { title: '日志管理' }
        },
        {
          path: '/system/data',
          name: 'data',
          component: Data,
          meta: { title: '数据管理' }
        },
        {
          path: '/system/performance',
          name: 'performance',
          component: Performance,
          meta: { title: '性能优化' }
        }
      ]
    },
    // 运营支持
    {
      path: '/support',
      component: MainLayout,
      redirect: '/support/ticket',
      children: [
        {
          path: '/support/ticket',
          name: 'ticket',
          component: Ticket,
          meta: { title: '工单管理' }
        },
        {
          path: '/support/announcement',
          name: 'announcement',
          component: Announcement,
          meta: { title: '公告管理' }
        },
        {
          path: '/support/knowledge',
          name: 'knowledge',
          component: Knowledge,
          meta: { title: '知识库' }
        },
        {
          path: '/support/customer',
          name: 'customer',
          component: Customer,
          meta: { title: '客户支持' }
        }
      ]
    },
    // 安全管理
    {
      path: '/security',
      component: MainLayout,
      redirect: '/security/permission',
      children: [
        {
          path: '/security/permission',
          name: 'permission',
          component: Permission,
          meta: { title: '权限管理' }
        },
        {
          path: '/security/monitor',
          name: 'security-monitor',
          component: SecurityMonitor,
          meta: { title: '安全监控' }
        },
        {
          path: '/security/compliance',
          name: 'compliance',
          component: Compliance,
          meta: { title: '合规管理' }
        }
      ]
    },
    // 404页面
    {
      path: '/:pathMatch(.*)*',
      name: 'error',
      component: Error,
    }
  ],
})

export default router